2020-2021 Sunseeker Telemetry and Lighting System
adc10_a_ex4_signedData.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
68 //******************************************************************************
69 
70 #include "driverlib.h"
71 
72 void main (void)
73 {
74  //Stop Watchdog Timer
75  WDT_A_hold(WDT_A_BASE);
76 
77  //Set P1.0 to output direction
78  GPIO_setAsOutputPin(
79  GPIO_PORT_P1,
80  GPIO_PIN0
81  );
82 
83  //Initialize the ADC10_A Module
84  /*
85  * Base Address for the ADC10_A Module
86  * Use internal ADC10_A bit as sample/hold signal to start conversion
87  * USE MODOSC 5MHZ Digital Oscillator as clock source
88  * Use default clock divider of 1
89  */
90  ADC10_A_init(ADC10_A_BASE,
91  ADC10_A_SAMPLEHOLDSOURCE_SC,
92  ADC10_A_CLOCKSOURCE_ADC10OSC,
93  ADC10_A_CLOCKDIVIDER_1);
94 
95  ADC10_A_enable(ADC10_A_BASE);
96 
97  /*
98  * Base Address for the ADC10_A Module
99  * Sample/hold for 16 clock cycles
100  * Do not enable Multiple Sampling
101  */
102  ADC10_A_setupSamplingTimer(ADC10_A_BASE,
103  ADC10_A_CYCLEHOLD_16_CYCLES,
104  ADC10_A_MULTIPLESAMPLESDISABLE);
105  //Convert data into signed, 2's complement format
106  ADC10_A_setDataReadBackFormat(ADC10_A_BASE,
107  ADC10_A_SIGNED_2SCOMPLEMENT);
108 
109  //Configure Memory Buffer
110  /*
111  * Base Address for the ADC10_A Module
112  * Use input A1
113  * Use positive reference of AVcc
114  * Use negative reference of AVss
115  */
116  ADC10_A_configureMemory(ADC10_A_BASE,
117  ADC10_A_INPUT_A1,
118  ADC10_A_VREFPOS_AVCC,
119  ADC10_A_VREFNEG_AVSS);
120 
121  //Enable Memory Buffer Interrupt
122  ADC10_A_clearInterrupt(ADC10_A_BASE,
123  ADC10IFG0);
124  ADC10_A_enableInterrupt(ADC10_A_BASE,
125  ADC10IE0);
126 
127  while (1)
128  {
129  __delay_cycles(5000);
130 
131  //Enable and Start the conversion
132  //in Single-Channel, Single-Conversion Mode
133  ADC10_A_startConversion(ADC10_A_BASE,
134  ADC10_A_SINGLECHANNEL);
135 
136  //LPM0, ADC10_A_ISR will force exit
137  __bis_SR_register(CPUOFF + GIE);
138  //For debug only
139  __no_operation();
140 
141 
142  }
143 }
144 
145 // ADC10_A interrupt service routine
146 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
147 __interrupt
148 #elif defined(__GNUC__)
149 __attribute__((interrupt(ADC10_VECTOR)))
150 #endif
151 void ADC10_A_ISR (void) {
152 
153  switch (__even_in_range(ADC10IV,12)){
154  case 0: break; //No interrupt
155  case 2: break; //conversion result overflow
156  case 4: break; //conversion time overflow
157  case 6: break; //ADC10HI
158  case 8: break; //ADC10LO
159  case 10: break; //ADC10IN
160  case 12: //ADC10IFG0
161  //Move Results from Memory Buffer
162  //(Automatically clears ADC10IFG0 by reading memory buffer)
163  if (ADC10_A_getResults(ADC10_A_BASE) < 0){
164  //Clear P1.0 LED off
165  GPIO_setOutputLowOnPin(GPIO_PORT_P1,
166  GPIO_PIN0
167  );
168  } else {
169  //Set P1.0 LED on
171  GPIO_PORT_P1,
172  GPIO_PIN0
173  );
174  }
175  //Clear CPUOFF bit from 0(SR)
177  break;
178  default: break;
179  }
180 }
void ADC10_A_ISR(void)
void main(void)
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)
GPIO_setOutputHighOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)
__delay_cycles(500000)